package main

import "fmt"

func main() {
	/*
		类似java throw异常 会终止线程
		panic之前进栈的才可以defer
		recover类似catch 已进栈defer会先出栈 方法栈退出 后续正常执行
	*/
	defer fmt.Println("defer")
	deferFunc()
	defer fmt.Println("defer3")
}

func deferFunc() {
	defer func() {
		if msg := recover(); msg != nil {
			fmt.Println("恢复")
		}
	}()
	fmt.Println("正常逻辑")
	defer fmt.Println("defer2")
	panic("慌得一批")
}
